package com.spm.librarianmanagersystem.mapper;

import com.spm.librarianmanagersystem.pojo.Borrow;
import com.spm.librarianmanagersystem.vo.borrowDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BorrowMapper {

    Boolean borrowBook(borrowDetail borrow);

    Borrow getBorrowRecordByNumber(Integer borrowingId);

    List<Borrow> getBorrowingList(String currentUserId);

    List<Borrow> getBorrowHistory(String currentUserId);

    List<Borrow> getBorrowingListByUserId(Integer userId);

    Integer getBorrowNum(Integer userId);

    Boolean deleteAllByUserID(Integer userID);

    Borrow getLastReturned(Integer userID);

    Integer getBorrowNumAll();

    Integer getBorrowCount(String isbn);

    @Select("SELECT COUNT(*) FROM borrow WHERE ISBN=#{isbn} AND book_id=#{bookId} AND status=0")
    Integer getUnreturnedCountByBookId(String isbn, Integer bookId);
//    @Select("SELECT * FROM borrow WHERE user_id = #{userID}")
//    List<Borrow> getBorrowingByUserID(Integer userID);

    Boolean updateScore(Integer borrowingId, Double score);

    Double getAverageScoreByBookId(String ISBN);
}
